package com.ruoyi.yl.bedSetting.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yl.bedSetting.vo.YlRoomFacilityVo;
import com.ruoyi.yl.bedSetting.service.IYlRoomFacilityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 房间设施Controller
 *
 * @author Ming
 * @date 2025-10-22
 */
@Api(tags = "房间设施Controller")
@RestController
@RequestMapping("/yl/roomFacility")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class YlRoomFacilityController extends BaseController {

    private final IYlRoomFacilityService ylRoomFacilityService;

    @ApiOperation("查询房间设施列表")
    @PreAuthorize("@ss.hasPermi('yl:roomFacility:list')")
    @GetMapping("/list")
    public TableDataInfo<YlRoomFacilityVo> list(YlRoomFacilityVo entity) {
        return ylRoomFacilityService.queryList(entity);
    }

    @ApiOperation("查询房间设施所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(YlRoomFacilityVo entity) {
        return AjaxResult.success("查询成功", ylRoomFacilityService.queryAll(entity));
    }

    @ApiOperation("导出房间设施列表")
    @PreAuthorize("@ss.hasPermi('yl:roomFacility:export')")
    @Log(title = "房间设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YlRoomFacilityVo entity) {
        List<YlRoomFacilityVo> list = ylRoomFacilityService.queryAll(entity);
        ExcelUtil<YlRoomFacilityVo> util = new ExcelUtil<>(YlRoomFacilityVo.class);
        util.exportExcel(response, list, "房间设施数据");
    }

    @ApiOperation("获取房间设施详细信息")
    @PreAuthorize("@ss.hasPermi('yl:roomFacility:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", ylRoomFacilityService.queryById(id));
    }

    @ApiOperation("新增房间设施")
    @PreAuthorize("@ss.hasPermi('yl:roomFacility:add')")
    @Log(title = "房间设施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YlRoomFacilityVo entity) {
        return toAjax(ylRoomFacilityService.save(entity));
    }

    @ApiOperation("修改房间设施")
    @PreAuthorize("@ss.hasPermi('yl:roomFacility:edit')")
    @Log(title = "房间设施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YlRoomFacilityVo entity) {
        return toAjax(ylRoomFacilityService.updateById(entity));
    }

    @ApiOperation("删除房间设施")
    @PreAuthorize("@ss.hasPermi('yl:roomFacility:remove')")
    @Log(title = "房间设施", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ylRoomFacilityService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
